package com.example.test;

import com.example.aop.AopTest;
import com.example.jdbc.BookDao;
import com.example.jdbc.EmpDao;
import com.example.jdbc.TestTxService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainTest2 {

    @Test
    public void testGen() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-6.xml");
        Object userService = context.getBean("userService");

        context.close();
    }

    @Test
    public void testAop() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-aop.xml");
        AopTest testAop = (AopTest)context.getBean("aopTest");
        //int add = testAop.add(1, 2);
        //System.out.println(add);
        testAop.div(1, 0);
    }

    @Test
    public void testJdbc() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-jdbc.xml");
        EmpDao dao = context.getBean(EmpDao.class);
        //dao.add();
        //dao.get();
        BookDao bookDao = context.getBean(BookDao.class);
        //bookDao.add();
        bookDao.add2();
    }


    @Test
    public void testTx() {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-jdbc.xml");
        TestTxService service = context.getBean(TestTxService.class);
        service.testTx();
    }
}
